<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>MessageChannel (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>

  <script type="text/javascript" src="//www.google.com/jsapi"></script>
  <script type="text/javascript">
     google.load("visualization", "1", {packages:["orgchart"]});
     var _loadingVisualizations = true;
  </script>

  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
        <span class="fn">messaging.MessageChannel</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    <span class='nodesc'>No description.</span>
  </div>


        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="local_closure_goog_messaging_messagechannel.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/local/closure/goog/messaging/messagechannel.js">Git</a></li>
          </ol>
        </div>
</div>






<h2 class="g-first">Inheritance</h2>
<div class='gviz-org-chart-container goog-inline-block'>
<table class='gviz-org-chart' style='display:none'>
  <tr><td>goog.messaging.MessageChannel</td><td></td></tr>
</table>
</div>
<div class='gviz-org-chart-container goog-inline-block'>
<table class='gviz-org-chart' style='display:none'>
</table>
</div>




  <h2>Constructor</h2>
      <div class="fn-constructor">
    goog.messaging.MessageChannel(<span></span>)
  </div>



<h2>Instance Methods</h2>


  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>







<div>
       <div class="desc">
         Defined in
         <span class="fn-name">
            <a href="interface_goog_messaging_MessageChannel.html">
              goog.messaging.MessageChannel
            </a>
         </span>
       </div>






<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.MessageChannel.prototype.connect"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">connect<span class="args">(<span class="arg">opt_connectCb</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Initiates the channel connection. When this method is called, all the
information needed to connect the channel has to be available.

Implementers should only require this method to be called if the channel
needs to be configured in some way between when it's created and when it
becomes active. Otherwise, the channel should be immediately active and this
method should do nothing but immediately call opt_connectCb.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">opt_connectCb</span>
        : <span class="type">Function=</span>
        <div class="entryOverview">Called when the channel has been connected
    and is ready to use.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_messaging_messagechannel.js.source.html#line56">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.MessageChannel.prototype.isConnected"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">isConnected<span class="args">()</span>
        </span>
        &#8658; <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span>
      </div>


     <div class="entryOverview">
       Gets whether the channel is connected.

If <code> #connect</code> is not required for this class, this should always return
true. Otherwise, this should return true by the time the callback passed to
<code> #connect</code> has been called and always after that.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span>&nbsp;
            Whether the channel is connected.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_messaging_messagechannel.js.source.html#line68">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.MessageChannel.prototype.registerDefaultService"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">registerDefaultService<span class="args">(<span class="arg">callback</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Registers a service to be called when a message is received that doesn't
match any other services.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">callback</span>
        : <span class="type">function(string, (string</span><span>&nbsp;|&nbsp;</span><span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>))
        <div class="entryOverview">The callback to process
    the incoming messages. Passed the service name and the payload. Since
    some channels can pass objects natively, the payload may be either an
    object or a string.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_messaging_messagechannel.js.source.html#line101">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.MessageChannel.prototype.registerService"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">registerService<span class="args">(<span class="arg">serviceName</span>,&nbsp;<span class="arg">callback</span>,&nbsp;<span class="arg">opt_objectPayload</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Registers a service to be called when a message is received.

Implementers shouldn't impose any restrictions on the service names that may
be registered. If some services are needed as control codes,
<code> goog.messaging.MultiMessageChannel</code> can be used to safely split the
channel into "public" and "control" virtual channels.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">serviceName</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">The name of the service.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">callback</span>
        : <span class="type">function((string</span><span>&nbsp;|&nbsp;</span><span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>))
        <div class="entryOverview">The callback to process the
    incoming messages. Passed the payload. If opt_objectPayload is set, the
    payload is decoded and passed as an object.</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">opt_objectPayload</span>
        : <span class="type">boolean=</span>
        <div class="entryOverview">If true, incoming messages for this
    service are expected to contain an object, and will be deserialized from
    a string automatically if necessary. It's the responsibility of
    implementors of this class to perform the deserialization.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_messaging_messagechannel.js.source.html#line88">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.MessageChannel.prototype.send"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryName">send<span class="args">(<span class="arg">serviceName</span>,&nbsp;<span class="arg">payload</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Sends a message over the channel.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">serviceName</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">The name of the service this message should be
    delivered to.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">payload</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span><span>&nbsp;|&nbsp;</span><span>!</span><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span>
        <div class="entryOverview">The value of the message. If this is an
    Object, it is serialized to a string before sending if necessary. It's
    the responsibility of implementors of this class to perform the
    serialization.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_messaging_messagechannel.js.source.html#line115">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>
</div>




















<div class="section">
  <table class="horiz-rule">


  </table>
</div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>
      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Package messaging</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">Package Reference</h2>
            <div id="sideTypeIndex" rootPath="" current="messaging.MessageChannel"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
